from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-12 14:16:29.562288
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 12, Oct, 2022
Time: 14:16:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6827
Nobs: 807.000 HQIC: -51.0052
Log likelihood: 10445.9 FPE: 5.77369e-23
AIC: -51.2062 Det(Omega_mle): 5.16793e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296453 0.052677 5.628 0.000
L1.Burgenland 0.109129 0.035432 3.080 0.002
L1.Kärnten -0.106475 0.018866 -5.644 0.000
L1.Niederösterreich 0.210072 0.074104 2.835 0.005
L1.Oberösterreich 0.099905 0.071088 1.405 0.160
L1.Salzburg 0.251061 0.037767 6.648 0.000
L1.Steiermark 0.038278 0.049429 0.774 0.439
L1.Tirol 0.106455 0.040083 2.656 0.008
L1.Vorarlberg -0.059095 0.034455 -1.715 0.086
L1.Wien 0.058730 0.063452 0.926 0.355
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064054 0.109047 0.587 0.557
L1.Burgenland -0.033627 0.073348 -0.458 0.647
L1.Kärnten 0.047807 0.039056 1.224 0.221
L1.Niederösterreich -0.172490 0.153405 -1.124 0.261
L1.Oberösterreich 0.385401 0.147160 2.619 0.009
L1.Salzburg 0.286990 0.078182 3.671 0.000
L1.Steiermark 0.106015 0.102325 1.036 0.300
L1.Tirol 0.313511 0.082977 3.778 0.000
L1.Vorarlberg 0.025317 0.071326 0.355 0.723
L1.Wien -0.016336 0.131354 -0.124 0.901
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189896 0.027039 7.023 0.000
L1.Burgenland 0.090214 0.018187 4.960 0.000
L1.Kärnten -0.008428 0.009684 -0.870 0.384
L1.Niederösterreich 0.264522 0.038037 6.954 0.000
L1.Oberösterreich 0.126366 0.036489 3.463 0.001
L1.Salzburg 0.047552 0.019386 2.453 0.014
L1.Steiermark 0.017035 0.025372 0.671 0.502
L1.Tirol 0.094248 0.020575 4.581 0.000
L1.Vorarlberg 0.059327 0.017686 3.355 0.001
L1.Wien 0.120329 0.032570 3.694 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110007 0.027710 3.970 0.000
L1.Burgenland 0.044254 0.018639 2.374 0.018
L1.Kärnten -0.016095 0.009925 -1.622 0.105
L1.Niederösterreich 0.192924 0.038982 4.949 0.000
L1.Oberösterreich 0.294189 0.037396 7.867 0.000
L1.Salzburg 0.115102 0.019867 5.794 0.000
L1.Steiermark 0.099852 0.026002 3.840 0.000
L1.Tirol 0.116279 0.021086 5.515 0.000
L1.Vorarlberg 0.070661 0.018125 3.899 0.000
L1.Wien -0.027556 0.033379 -0.826 0.409
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127609 0.050311 2.536 0.011
L1.Burgenland -0.051507 0.033841 -1.522 0.128
L1.Kärnten -0.040477 0.018019 -2.246 0.025
L1.Niederösterreich 0.169914 0.070777 2.401 0.016
L1.Oberösterreich 0.137228 0.067895 2.021 0.043
L1.Salzburg 0.284308 0.036071 7.882 0.000
L1.Steiermark 0.035085 0.047210 0.743 0.457
L1.Tirol 0.164752 0.038283 4.303 0.000
L1.Vorarlberg 0.104065 0.032908 3.162 0.002
L1.Wien 0.071219 0.060603 1.175 0.240
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060479 0.039846 1.518 0.129
L1.Burgenland 0.038635 0.026801 1.442 0.149
L1.Kärnten 0.050707 0.014271 3.553 0.000
L1.Niederösterreich 0.225838 0.056054 4.029 0.000
L1.Oberösterreich 0.282515 0.053773 5.254 0.000
L1.Salzburg 0.051217 0.028568 1.793 0.073
L1.Steiermark -0.007274 0.037390 -0.195 0.846
L1.Tirol 0.149670 0.030320 4.936 0.000
L1.Vorarlberg 0.070911 0.026063 2.721 0.007
L1.Wien 0.078264 0.047997 1.631 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178204 0.047624 3.742 0.000
L1.Burgenland -0.005969 0.032033 -0.186 0.852
L1.Kärnten -0.061140 0.017057 -3.585 0.000
L1.Niederösterreich -0.083839 0.066996 -1.251 0.211
L1.Oberösterreich 0.192319 0.064269 2.992 0.003
L1.Salzburg 0.056422 0.034144 1.652 0.098
L1.Steiermark 0.230997 0.044688 5.169 0.000
L1.Tirol 0.493858 0.036238 13.628 0.000
L1.Vorarlberg 0.049549 0.031150 1.591 0.112
L1.Wien -0.048102 0.057366 -0.839 0.402
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162116 0.054680 2.965 0.003
L1.Burgenland -0.011481 0.036779 -0.312 0.755
L1.Kärnten 0.065964 0.019584 3.368 0.001
L1.Niederösterreich 0.200392 0.076923 2.605 0.009
L1.Oberösterreich -0.061017 0.073792 -0.827 0.408
L1.Salzburg 0.216026 0.039203 5.510 0.000
L1.Steiermark 0.113866 0.051310 2.219 0.026
L1.Tirol 0.076862 0.041608 1.847 0.065
L1.Vorarlberg 0.124517 0.035766 3.481 0.000
L1.Wien 0.114846 0.065866 1.744 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353942 0.031833 11.119 0.000
L1.Burgenland 0.006088 0.021412 0.284 0.776
L1.Kärnten -0.023533 0.011401 -2.064 0.039
L1.Niederösterreich 0.223785 0.044782 4.997 0.000
L1.Oberösterreich 0.175166 0.042959 4.078 0.000
L1.Salzburg 0.047228 0.022823 2.069 0.039
L1.Steiermark -0.016964 0.029871 -0.568 0.570
L1.Tirol 0.108578 0.024223 4.482 0.000
L1.Vorarlberg 0.073548 0.020822 3.532 0.000
L1.Wien 0.053450 0.038345 1.394 0.163
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041183 0.152624 0.190273 0.157772 0.124674 0.113957 0.065677 0.226550
Kärnten 0.041183 1.000000 -0.002557 0.129720 0.041489 0.096040 0.429609 -0.053118 0.101230
Niederösterreich 0.152624 -0.002557 1.000000 0.336967 0.154563 0.300597 0.111035 0.183780 0.327747
Oberösterreich 0.190273 0.129720 0.336967 1.000000 0.231971 0.332606 0.172600 0.172476 0.263131
Salzburg 0.157772 0.041489 0.154563 0.231971 1.000000 0.145418 0.127091 0.148852 0.134548
Steiermark 0.124674 0.096040 0.300597 0.332606 0.145418 1.000000 0.153242 0.140975 0.080033
Tirol 0.113957 0.429609 0.111035 0.172600 0.127091 0.153242 1.000000 0.114876 0.155244
Vorarlberg 0.065677 -0.053118 0.183780 0.172476 0.148852 0.140975 0.114876 1.000000 0.007182
Wien 0.226550 0.101230 0.327747 0.263131 0.134548 0.080033 0.155244 0.007182 1.000000